Newer
Older
EARS-LINUX / KIOSK setup / kiosk-session.sh
#!/bin/bash
# Kiosk session. Exits when the app exits.

APP_DIR="/home/ears/Desktop/Kazi/v3/linux/"
APP_CMD="mono program.exe"
DISPLAY_SETUP="/home/ears/rotate.sh"

LOG_DIR="$HOME/kiosk/logs"
mkdir -p "$LOG_DIR"
SESSION_LOG="$LOG_DIR/session-$(date +%Y%m%d-%H%M%S).log"
ln -sfn "$SESSION_LOG" "$LOG_DIR/current.log"
ls -1t "$LOG_DIR"/session-*.log 2>/dev/null | tail -n +21 | xargs -r rm -f

exec > >(tee -a "$SESSION_LOG") 2>&1
echo "=== session start $(date -Is) ==="

# no blanking, no screensaver, no pointer
cd "$APP_DIR" || { echo "FATAL: $APP_DIR not found"; sleep 20; exit 1; }

# --- hardware setup, shared with the Xubuntu session ---
if [[ -x "$DISPLAY_SETUP" ]]; then
    echo "--- running display-setup.sh ---"
    "$DISPLAY_SETUP"
else
    echo "WARNING: $DISPLAY_SETUP missing, using fallback"
    xset s off; xset s noblank; xset -dpms
fi

unclutter -idle 0 -root &
matchbox-window-manager -use_titlebar no -use_cursor no &

cd "$APP_DIR" || { echo "FATAL: $APP_DIR not found"; sleep 20; exit 1; }

recovery_console() {
    echo "=== crash loop, opening recovery console ==="
    xterm -fa Monospace -fs 14 -geometry 130x42 -T "kiosk recovery" -e bash -c "
        echo 'The app failed to start 3 times in a row.'
        echo 'Last 60 lines of $SESSION_LOG:'
        echo '--------------------------------------------------'
        tail -n 60 '$SESSION_LOG'
        echo '--------------------------------------------------'
        echo
        echo 'Shell below. Type exit to retry the app.'
        exec bash
    "
}

fails=0
while true; do
    started=$SECONDS
    $APP_CMD
    code=$?
    ran=$(( SECONDS - started ))
    echo "=== app exited $code after ${ran}s ==="

    # Clean exit (the Close button) ends the kiosk session.
    if (( code == 0 )); then
        echo "=== clean exit, leaving kiosk ==="
        exit 0
    fi

    if (( ran < 20 )); then (( fails++ )); else fails=1; fi
    if (( fails >= 3 )); then
        fails=0
        recovery_console
    fi
    sleep 2
done